import { useCallback, useRef } from 'react';

const useRefState = initValue => {
  const ref = useRef(initValue);
  const setState = useCallback(arg => {
    if (typeof arg === 'function') {
      ref.current = arg(ref.current);
      return;
    }

    ref.current = arg;
  }, []);

  return [ref, setState];
};

export default useRefState;
